package com.etoak.stock.controller;

import com.etoak.stock.pojo.domin.SysPermissionDomain;
import com.etoak.stock.pojo.domin.SysPermissionTreeDomain;
import com.etoak.stock.service.PermissionService;
import com.etoak.stock.vo.req.PermissionAddVo;
import com.etoak.stock.vo.req.PermissionUpdateVo;
import com.etoak.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author by 孙有泽
 * @Date 2024/11/11 13:16
 * @Description 权限管理控制层
 */
@RestController
@RequestMapping("/api")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    /*
     * @author 孙有泽
     * @date 2024/11/11 13:17
     * @description 查询所有权限集合
     */
    @GetMapping("/permissions")
    public R<List<SysPermissionDomain>> getAllPermission(){
        return permissionService.getAllPermission();
    };
    /*
     * @author 孙有泽
     * @date 2024/11/11 13:38
     * @description 添加权限时回显权限树,仅仅显示目录和菜单
     */
    @GetMapping("/permissions/tree")
    public R<List<SysPermissionTreeDomain>> getAllPermissionTree() {
         return permissionService.getAllPermissionTree();
    }
    /*
     * @author 孙有泽
     * @date 2024/11/12 21:22
     * @description   添加角色和角色关联权限
     */

    @PostMapping("/permission")
    public R addPermission(@RequestBody PermissionAddVo  permissionAddVo){
        return permissionService.addPermission(permissionAddVo);
    }
    /*
     * @author 孙有泽
     * @date 2024/11/12 21:23
     * @description  更新权限
     */

    @PutMapping("/permission")
    public R updatePermission(@RequestBody PermissionUpdateVo permissionUpdateVo){
        return permissionService.updatePermission(permissionUpdateVo);
    }

    /*
     * @author 孙有泽
     * @date 2024/11/12 21:29
     * @description 删除权限
     */
    @DeleteMapping("/permission/{permissionId}")
    public R deletePermission(@PathVariable("permissionId") Long permissionId){
        return permissionService.deletePermission(permissionId);
    }
}
